<template>
	<view class="content">
		<view class="header">个人中心</view>
		<view class="flex tit" v-if="!token" @click="login">
			<img src="@/static/images/person/man.jpg" />登录
		</view>
		<view class="flex tit" v-else>
			<img :src="userinfo.avatar" />{{ userinfo.nickname }}
		</view>
		<view class="myHandle">
			<view class="myHandleItem" v-for="(item, i) in list" :key="i" @click="routerTo(item.path)">
				{{item.num}}
				<text>{{ item.name }}</text>
			</view>
		</view>
		<!--认证-->
		<view @click="routerTo('/pages/person/authentication')" class="identification">
			<img class="rz" src="@/static/images/person/rz.png" />
			<text class="text">未认证</text>
			<text>实名认证或企业认证</text>
			<img class="go" src="@/static/images/person/go.jpg" />
		</view>

		<view class="cg cg1">
			<view class="title"> 采购订单</view>
			<view class="order">
				<view class="orderItem" @click="go('/pages/person/orderList?status='+item.status)"
					v-for="(item, i) in orderList" :key="i">
					<img :src="require(`@/static/images/person/order${i}.jpg`)" />
					<text>{{ item.name }}</text>
				</view>
			</view>
		</view>
		<view class="cg">
			<view class="title">鉴定订单</view>
			<view class="order">
				<view class="orderItem" @click="go('/pages/person/jdorderlist?status='+item.status)"
					v-for="(item, i) in jdOrderList" :key="i">
					<img :src="require(`@/static/images/person/jd${i}.jpg`)" />
					<text>{{ item.name }}</text>
				</view>
			</view>
		</view>
		<!--大厅-->
		<view class="hall">
			<view class="hallItem" @click="gou(1)">
				<view class="info">
					<text>供货大厅</text>
					xxxxxxx
				</view>
				<u-icon name="arrow-right"></u-icon>
			</view>
			<view class="hallItem" @click="gou(2)">
				<view class="info">
					<text>求购大厅</text>
					xxxxxxx
				</view>
				<u-icon name="arrow-right"></u-icon>
			</view>
		</view>
		<!--        列表-->
		<view class="list">
			<view @click="routerTo(item.path)" class="listItem" v-for="(item, i) in lists" :key="i">
				<img :src="require(`@/static/images/person/list${i}.jpg`)" />
				<text> {{ item.name }}</text>

				<u-icon name="arrow-right"></u-icon>
			</view>
		</view>
		<tabar :active="4" class="tabar" />
	</view>
</template>
<script>
	import tabar from "@/components/tabar.vue";
	export default {
		name: "index",
		components: {
			tabar,
		},
		data() {
			return {
				lists: [{
						name: "成为加盟商",
						src: "",
						path: ""
					},
					{
						name: "在线客服",
						src: "",
						path: ""
					},
					{
						name: "意见反馈",
						src: "",
						path: "/pages/person/feedBack"
					},
					{
						name: "地址管理",
						src: "",
						path: "/pages/person/addressList"
					},
				],
				hallList: [{
					name: "供货大厅"
				}, {
					name: "求购大厅"
				}],
				list: [{
						name: "我的发布",
						num:0,
						path: "/pages/person/myPosts?current=0"
					},
					{
						name: "我的求购",
						num:0,
						path: "/pages/person/myPosts?current=1"
					},
					{
						name: "我的收藏",
						num:0,
						path: "/pages/person/follow"
					},
					{
						name: "我的足迹",
						num:0,
						path:"/pages/person/foot"
					},
				],
				orderList: [{
						name: "已取消",
						status: -1
					},
					{
						name: "待付款",
						status: 0
					},
					{
						name: "待发货",
						status: 1
					},
					{
						name: "待收货",
						status: 2
					},
					{
						name: "已完成",
						status: 3
					},
					{
						name: "去售后",
						status: 4
					},
				],
				jdOrderList: [{
						name: "待支付",
						status: 0
					},
					{
						name: "待取货",
						status: 1
					},
					{
						name: "已取货",
						status: 2
					},
					{
						name: "待收货",
						status: 3
					},
					{
						name: "鉴定中",
						status: 4
					},
					{
						name: "已完成",
						status: 5
					},
				],
				userinfo: "",
				token: uni.getStorageSync("token"),
				minedata: {},
			};
		},
		onShow() {
			// this.isjia = this.$.isjia
			// uni.setStorageSync("token", "c8d60913-d83b-4c04-8674-5b9be1c2aab6");
			this.getuserinfo();
			this.getminedata();
		},
		methods: {
			gou(e) {
				uni.setStorageSync("getjump", e)
				uni.switchTab({
					url: '/pages/buy/index'
				})
			},
			getminedata() {
				this.$.ajax(1, "POST", "/user/get_mine_data", {
					type: 0
				}, (res) => {
					if (res.code == 1) {
						this.list[0].num = res.data.fabu
						this.list[1].num = res.data.qiugou
						this.list[2].num = res.data.follownum
						this.list[3].num = res.data.footnum
					}
				});
			},
			getuserinfo() {
				this.$.ajax(1, "POST", "/user/get_user_info", {
					type: 0
				}, (res) => {
					if (res.code == 1) {
						this.userinfo = res.data.userinfo;
					}
				});
			},
			login() {
				var that = this;
				uni.login({
					provider: "weixin", //使用微信登录
					success: function(loginRes) {
						var code = loginRes.code;
						console.log(code);
						uni.getUserInfo({
							provider: "weixin",
							success: function(infoRes) {
								console.log(infoRes);
								console.log("用户昵称为：" + infoRes.userInfo.nickName);
								var encryptedData = infoRes.encryptedData;
								var iv = infoRes.iv;
								var signature = infoRes.signature;
								var datas = {
									code: code,
									encryptedData: encryptedData,
									iv: iv,
									signature: signature,
									pid: that.pid,
								};
								// that.qingqiu(datas,'https://shunc.lingtinglvxing.com/api/user/minilogin')
								that.$.ajax(1, "POST", "/user/minilogin", datas, (res) => {
									console.log(res.data.userinfo.token);
									if (res.code == 1) {
										that.userinfo = res.data.userinfo;
										that.token = res.data.userinfo.token;
										uni.setStorageSync("token", res.data.userinfo
											.token);
										that.getuserinfo();
										// setTimeout(()=>{
										// 	uni.navigateBack()
										// },1000)
										// that.jingang = res.data.jingang
										// that.zhongbu = res.data.zhongbu
										// that.bgimage = res.data.index_image
									} else {
										that.$.ti_shi(res.msg);
									}
								});
							},
						});
					},
				});
			},
			go(e) {
				uni.navigateTo({
					url: e
				});
			},
			routerTo(url) {
				if (!url) return;
				uni.navigateTo({
					url
				});
			},
		},
		created() {},
		mounted() {},
	};
</script>
<style lang="scss" scoped>
	.content {
		padding: 20rpx 20rpx 120rpx 20rpx;

		background-image: url("@/static/images/home/bg.jpg");
		background-repeat: no-repeat;
		background-size: 100% auto;

		.list {
			margin: 20rpx 0;
			background-color: #fff;
			padding: 10rpx 30rpx 30rpx 30rpx;
			border-radius: 8rpx;
			border-radius: 12rpx;

			.listItem {
				padding: 30rpx 0rpx;
				border-bottom: 1rpx solid #f4f4f4;
				display: flex;
				align-items: center;
				gap: 20rpx;
				font-size: 26rpx;

				text {
					flex: 1;
				}

				img {
					width: 20px;
					height: 20px;
				}
			}
		}

		.listItem:last-child {
			border: none;
			padding-bottom: 0;
		}

		.hall {
			display: flex;
			gap: 20rpx;
			margin: 20rpx 0;

			.hallItem {
				flex: 1;
				background-color: #fff;
				padding: 20rpx;
				border-radius: 8rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				height: 144rpx;

				.info {
					display: flex;
					flex-direction: column;
					gap: 20rpx;
					color: #666666;

					text {
						color: #131313;
						font-size: 32rpx;
						font-weight: 700;
					}
				}
			}
		}

		.identification {
			display: flex;
			align-items: center;
			//justify-content: space-between;
			//背景颜色渐变 #1D51BF #0096FF
			border-radius: 24rpx 24rpx 0 0;
			background: linear-gradient(to right, #1d51bf, #0096ff);
			gap: 10rpx;
			padding: 40rpx;
			color: #ffffff;
			font-size: 20rpx;
			font-weight: 400;

			.rz {
				width: 36rpx;
				height: 36rpx;
			}

			.text {
				font-weight: 500;
				flex: 1;
				font-size: 26rpx;
			}

			.go {
				width: 58rpx;
				height: 38rpx;
			}
		}

		.cg {
			background-color: #ffffff;
			padding: 30rpx 20rpx 40rpx;
			border-radius: 12rpx;
			margin: 20rpx 0;

			.title {
				font-size: 28rpx;
				font-weight: 700;
			}

			.order {
				padding-top: 40rpx;
				display: flex;
				justify-content: space-between;

				.orderItem {
					display: flex;
					flex-direction: column;
					align-items: center;
					gap: 20rpx;

					//font-size: 18px;
					//font-weight: 700;
					img {
						width: 44rpx;
						height: 44rpx;
					}

					text {
						color: #666666;
						font-weight: 400;
						font-size: 24rpx;
					}
				}
			}
		}

		.cg1 {
			margin-top: -20rpx;
		}

		.myHandle {
			padding: 40rpx 0;
			display: flex;
			justify-content: space-around;

			.myHandleItem {
				display: flex;
				flex-direction: column;
				align-items: center;
				gap: 20rpx;
				font-size: 36rpx;
				font-weight: 700;

				text {
					color: #666666;
					font-weight: 400;
					font-size: 24rpx;
				}
			}
		}

		.header {
			text-align: center;
			padding: 60rpx 0;
		}

		.tit {
			gap: 20rpx;
			align-items: center;
			font-weight: 700;

			img {
				width: 84rpx;
				height: 84rpx;
				border-radius: 41rpx;
				font-weight: 500;
			}
		}
	}

	.tabar {
		width: 100%;
		height: 160rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 9999;
	}
</style>